********************************************************************************
************INDEPENDENT VARIABLE:GENDER (SEX)***********************************
********************************************************************************
* Variable: gndr 
tab gndr
* Recode so that Male = 2 and Female = 1
recode gndr (1=2) (2=1), generate (gender)
tab gender 

* Drop selected countries
drop if cntry == "IE"
drop if cntry == "IS"
drop if cntry == "LT"
drop if cntry == "LV"
drop if cntry == "ME"
drop if cntry == "IL"
drop if cntry == "UA"


********************************************************************************
************DEPENDENT VARIABLE: PRRvote*****************************************
********************************************************************************

* Generate PRR party vote- variable for each country 

* Bulgaria 
gen PRR_bu = 0
replace PRR_bu = 1 if prtvtfbg == 6

* Estonia
gen PRR_es = 0 
replace PRR_es = 1 if prtvtiee == 6

gen PRR_swe = 0
replace PRR_swe = 1 if prtvtese == 8 

*Austria 
gen PRR_au = 0
replace PRR_au = 1 if prtvtdat == 3

*Belgium 
gen PRR_be = 0
replace PRR_be = 1 if prtvtebe == 6

*Cyprus 
gen PRR_cy = 0
replace PRR_cy = 1 if prtvtccy == 9

*Croatia 
gen PRR_cr = 0
replace PRR_cr = 1 if prtvtchr == 3

*Germany AfD 
gen PRR_ge = 0 
replace PRR_ge = 1 if prtvgde1 == 6
tab PRR_ge 

*Finland 
gen PRR_fi = 0 
replace PRR_fi = 1 if prtvtffi == 8
tab prtvtffi
tab PRR_fi

*France 
gen PRR_fr = 0 
replace PRR_fr = 1 if prtvtffr == 8
replace PRR_fr = 1 if prtvtffr == 9

*Greece 
gen PRR_gr = 0 
replace PRR_gr = 1 if prtvtegr == 5
replace PRR_gr = 1 if prtvtegr == 6
tab PRR_gr 

*Hungary
gen PRR_hu = 0 
replace PRR_hu = 1 if prtvthhu == 6
tab PRR_hu

*Italy 
gen PRR_it = 0 
replace PRR_it = 1 if prtvteit == 1
replace PRR_it = 1 if prtvteit == 4
tab PRR_it 

*Netherlands
gen PRR_ne = 0 
replace PRR_ne = 1 if prtvtinl == 3
tab PRR_ne

*Norway 
gen PRR_no = 0 
replace PRR_no = 1 if prtvtcno == 8
tab PRR_no

*Poland 
gen PRR_po = 0 
replace PRR_po = 1 if prtvtfpl == 2
tab PRR_po

*Portugal
gen PRR_por = 0 
replace PRR_por = 1 if prtvtept == 5
tab PRR_por

*Serbia  
gen PRR_se = 0 
replace PRR_se = 1 if prtvtbrs == 4
replace PRR_se = 1 if prtvtbrs == 33
tab PRR_se 

*Slovakia 
gen PRR_slova = 0 
replace PRR_slova = 1 if prtvtesk == 4
tab PRR_slova

*Slovenia
gen PRR_slove = 0 
replace PRR_slove = 1 if prtvtgsi == 9
tab PRR_slove

*Spain 
gen PRR_sp = 0 
replace PRR_sp = 1 if prtvtges == 3
tab PRR_sp

*Switzerland 
gen PRR_swi = 0 
replace PRR_swi = 1 if prtvthch == 1
tab PRR_swi

*United Kingdom 
gen PRR_uk = 0 
replace PRR_uk = 1 if prtvtdgb == 7
tab PRR_uk

* Generate combined variable for all countries 
gen PRRvote = 0
replace PRRvote if PRR_bu = 1 
replace PRRvote if PRR_es = 1
replace PRRvote if PRR_swe = 1 
replace PRRvote if PRR_au = 1 
replace PRRvote if PRR_be = 1
replace PRRvote if PRR_cy = 1
replace PRRvote if PRR_cr = 1
replace PRRvote if PRR_fi = 1
replace PRRvote if PRR_fr = 1 
replace PRRvote if PRR_ge = 1
replace PRRvote if PRR_gr = 1
replace PRRvote if PRR_hu = 1
replace PRRvote if PRR_it = 1
replace PRRvote if PRR_ne = 1
replace PRRvote if PRR_no = 1
replace PRRvote if PRR_po = 1
replace PRRvote if PRR_por = 1
replace PRRvote if PRR_se = 1
replace PRRvote if PRR_slova = 1
replace PRRvote if PRR_slove = 1
replace PRRvote if PRR_sp = 1
replace PRRvote if PRR_swi = 1
replace PRRvote if PRR_uk = 1
tab PRRvote


********************************************************************************
************CONTROLS: LEVEL 1***************************************************
********************************************************************************

******Policy-vote theory*********
*********************************

*** Self placement - left/right: lrscale
tab lrscale 
tab lrscale, nolabel
* (standardize variable): 
sum lrscale  
gen st_lrscale = (lrscale -5.064514)/2.259487
sum st_lrscale

*** Allow many/few immigrants of different race/ethnic group from majority: imdfetn 
tab imdfetn
tab imdfetn, nolabel
gen allowim = imdfetn 
* (standardize variable): 
sum allowim  
gen st_allowim = (allowim -2.412343)/.9087094
sum st_allowim

******Discontent*****
*********************

*** Satisfaction with democracy: stfdem (scale)
tab stfdem 
recode stfdem  (0=10) (1=9) (2=8) (3=7) (4=6) (5=5) (6=4) (7=3) (8=2) (9=1) (10=0), generate (satisfieddem)
tab satisfieddem
* (standardize variable): 
sum satisfieddem
gen st_satisfieddem = (satisfieddem -4.925321)/2.595034
sum st_satisfieddem

* Satisfaction with government 
tab stfgov
recode stfgov (0=10) (1=9) (2=8) (3=7) (4=6) (5=5) (6=4) (7=3) (8=2) (9=1) (10=0), generate (satisfiedgov)
tab satisfiedgov
* (standardize variable): 
sum satisfiedgov
gen st_satisfiedgov= (satisfiedgov -5.962646)/2.51818
sum st_satisfiedgov

* Satisfaction with economy 
tab stfeco
recode stfeco (0=10) (1=9) (2=8) (3=7) (4=6) (5=5) (6=4) (7=3) (8=2) (9=1) (10=0), generate (satisfiedeco)
tab satisfiedeco
* (standardize variable): 
sum satisfiedeco
gen st_satisfiedeco= (satisfiedeco -5.565641)/2.375756
sum st_satisfiedeco

* Create index 
gen index_discontent = (((satisfiedgov + satisfiedeco + satisfieddem) - 3*0) / (3*10)) * 100
sum index_discontent
scalar min_val = r(min)
scalar max_val = r(max)
gen index_discontent_scaled = 0 + (index_discontent - min_val) / (max_val - min_val) * 100
* standardising
sum index_discontent_scaled
gen st_index_discontent_scaled = (index_discontent_scaled -54.85999)/21.77999
sum st_index_discontent_scaled

******Socioeco*******
*********************

*** Highest level of education: eisced 
tab eisced 
tab eisced, nolabel 
recode eisced (55 = .), generate(education)
tab education 
* (standardize variable): 
sum education
gen st_education = (education -4.09897)/1.812346
sum st_education

*** Age 
tab agea 
* recode into 5 age groups 
gen age =.
replace age = 1 if agea >= 15 & agea < 30
replace age = 2 if agea >= 30 & agea < 45
replace age = 3 if agea >= 45 & agea < 60
replace age = 4 if agea >= 60 & agea < 75
replace age = 5 if agea >= 75 & agea <= 90
tab age
* (standardize variable): 
sum age
gen st_age = (age -2.979401)/1.254152
sum st_age

*** How religious are you: rlgdgr 
tab rlgdgr
* (standardize variable): 
sum rlgdgr
gen st_religious = (rlgdgr -4.668291)/3.17008
sum st_religious

********************************************************************************
************CONTROLS: LEVEL 2***************************************************
********************************************************************************

****PRR Party in government ****
********************************
gen prr_gov = 0
replace prr_gov = 1 if cntry == "HU"
replace prr_gov = 1 if cntry == "PL"
replace prr_gov = 1 if cntry == "IT"
replace prr_gov = 1 if cntry == "FI"
replace prr_gov = 1 if cntry == "CH"
tab prr_gov

****Ideological extremity (Manifesto variable)****
**************************************************
* Standardizing 
sum per601
gen st_per601 = (per601 -10.55871)/4.9645
sum st_per601

********************************************************************************
************MODERATOR: MAS/FEM CULTURE******************************************
********************************************************************************

** Masculine dimension **
tab ipshabt 
tab ipshabt, nolabel 
recode ipshabt (1=6) (2=5) (3=4) (4=3) (5=2) (6=1), generate (admireimp)
tab admireimp
* standardize variable: 
sum admireimp
gen st_admireimp = (admireimp -3.811523)/1.400972
sum st_admireimp

tab iprspot
tab iprspot, nolabel 
recode iprspot (1=6) (2=5) (3=4) (4=3) (5=2) (6=1), generate (respectimp)
tab respectimp
* standardize variable: 
sum respectimp
gen st_respectimp = (respectimp -3.858883)/1.386266
sum st_respectimp

tab ipsuces
tab ipsuces, nolabel 
recode ipsuces (1=6) (2=5) (3=4) (4=3) (5=2) (6=1), generate (successimp)
tab successimp
* standardize variable: 
sum successimp
gen st_successimp = (successimp -3.836728)/1.371087
sum st_successimp

tab imprich
tab imprich, nolabel 
recode imprich (1=6) (2=5) (3=4) (4=3) (5=2) (6=1), generate (richimp)
tab richimp
* standardize variable: 
sum richimp
gen st_richimp = (richimp -2.889496)/1.339509
sum st_richimp









